# collections
# 堆
from heapq import *
from random import shuffle

data = list(range(10))
shuffle(data)
print(data)

# 入堆
heap = []
for n in data:
    heappush(heap, n)

print(heap)  # [0, 2, 1, 5, 4, 6, 3, 8, 9, 7]

# 出堆
while heap:
    print(heappop(heap), end=',')  # 0,1,2,3,4,5,6,7,8,9,

#
print()

# 堆化
heap = [5, 8, 0, 3, 6, 7, 9, 1, 4, 2]
heapify(heap)
print(heap)
while heap:
    print(heappop(heap), end=',')  # 0,1,2,3,4,5,6,7,8,9,
print()

# heaprelace
heap = [5, 8, 0, 3, 6, 7, 9, 1, 4, 2]
heapify(heap)
heapreplace(heap, 0.5)
print(heap)
